#![allow(dead_code)]

struct FnOnceLrn {}

impl FnOnceLrn {
    pub fn hello() {
        println!("FnOnce learning!");
    }
}

#[cfg(test)]
mod tests {
    // use super::*;
    #[test]
    fn test_fn_once() {
        let x = String::from("x");
        let consume_and_return_x = move || x;
        consume_with_relish(consume_and_return_x);

        // 此时无法再调用 `consume_and_return_x`

        fn consume_with_relish<F>(func: F)
        where
            F: FnOnce() -> String,
        {
            // `func` 消耗其捕获的变量，因此不能多次运行。
            println!("Consumed: {}", func());
            println!("Delicious!");
            // 再次尝试调用 `func()` 将为 `func` 引发 `use of moved value` 错误。
        }
    }
}
